package cn.jdy.plugins.wap;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.platform.service.ConfService;
import cn.jdy.plugins.entity.NewsXysgajM;
import cn.jdy.plugins.entity.Productx;
import cn.jdy.plugins.service.xysgajM.NewsXysgajMService;

/**
 * daihu
 * @title 产品控制类
 */
@Controller
@RequestMapping("/laws")
public class LawsCtrl extends BaseCtrl {
  @Autowired
  private NewsXysgajMService newsxysgajmservice;
  @Autowired
  private ConfService confService;

  
  @RequestMapping("")
  public ModelAndView list(NewsXysgajM newsxysgajm){
    ModelAndView mv = new ModelAndView("/lawsList.jsp");
    newsxysgajm.setStatus("1");// 状态 0已发布、1已下架、2审核中、3审核不通过
    mv.addObject("dataList", newsxysgajmservice.querypagelaws(newsxysgajm));
    mv.addObject("iTotalDisplayRecords", newsxysgajmservice.count(newsxysgajm));
    mv.addObject("entity", newsxysgajm);
    mv.addObject("pid",newsxysgajm.getColumnId());
    return mv;
  }
  
  /**
   * 异步获取商品列表
   * @param productx
   * @param key
   * @param pid
   * @return
   */
  @RequestMapping("/loadMore")
  @ResponseBody
  public Map<String, Object> loadMore(NewsXysgajM newsxysgajm){
    Map<String, Object> jsonMap = new HashMap<String, Object>();
    try {
    	newsxysgajm.setStatus("1");// 状态 0已发布、1已下架、2审核中、3审核不通过
      jsonMap.put("dataList", newsxysgajmservice.querypage(newsxysgajm));
      jsonMap.put("iTotalDisplayRecords", newsxysgajmservice.count(newsxysgajm));
    } catch(Exception e) {
      BaseLog.e(this.getClass(), "查询异常", e);
    }
    return jsonMap;
  }
  
  /**
   * 产品详情
   * @param id
   * @return
   */
  @RequestMapping("/show-{id}.html")
  public ModelAndView queryDetail(@PathVariable Long id) {
    ModelAndView mv = new ModelAndView("/lawsDetail.jsp");
    mv.addObject("data", id==null||id==0 ? id : this.newsxysgajmservice.find(id));
    return mv;
  }
  
}
